package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPowerBatteryModel;
import com.ruoyi.system.service.ITPowerBatteryModelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动力电池型号Controller
 * 
 * @author ruoyi
 * @date 2025-10-01
 */
@Controller
@RequestMapping("/system/model")
public class TPowerBatteryModelController extends BaseController
{
    private String prefix = "system/model";

    @Autowired
    private ITPowerBatteryModelService tPowerBatteryModelService;

    @RequiresPermissions("system:model:view")
    @GetMapping()
    public String model()
    {
        return prefix + "/model";
    }

    /**
     * 查询动力电池型号列表
     */
    @RequiresPermissions("system:model:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TPowerBatteryModel tPowerBatteryModel)
    {
        startPage();
        List<TPowerBatteryModel> list = tPowerBatteryModelService.selectTPowerBatteryModelList(tPowerBatteryModel);
        return getDataTable(list);
    }

    /**
     * 导出动力电池型号列表
     */
    @RequiresPermissions("system:model:export")
    @Log(title = "动力电池型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPowerBatteryModel tPowerBatteryModel)
    {
        List<TPowerBatteryModel> list = tPowerBatteryModelService.selectTPowerBatteryModelList(tPowerBatteryModel);
        ExcelUtil<TPowerBatteryModel> util = new ExcelUtil<TPowerBatteryModel>(TPowerBatteryModel.class);
        return util.exportExcel(list, "动力电池型号数据");
    }

    /**
     * 新增动力电池型号
     */
    @RequiresPermissions("system:model:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存动力电池型号
     */
    @RequiresPermissions("system:model:add")
    @Log(title = "动力电池型号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPowerBatteryModel tPowerBatteryModel)
    {
        return toAjax(tPowerBatteryModelService.insertTPowerBatteryModel(tPowerBatteryModel));
    }

    /**
     * 修改动力电池型号
     */
    @RequiresPermissions("system:model:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TPowerBatteryModel tPowerBatteryModel = tPowerBatteryModelService.selectTPowerBatteryModelById(id);
        mmap.put("tPowerBatteryModel", tPowerBatteryModel);
        return prefix + "/edit";
    }

    /**
     * 修改保存动力电池型号
     */
    @RequiresPermissions("system:model:edit")
    @Log(title = "动力电池型号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPowerBatteryModel tPowerBatteryModel)
    {
        return toAjax(tPowerBatteryModelService.updateTPowerBatteryModel(tPowerBatteryModel));
    }

    /**
     * 删除动力电池型号
     */
    @RequiresPermissions("system:model:remove")
    @Log(title = "动力电池型号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tPowerBatteryModelService.deleteTPowerBatteryModelByIds(ids));
    }
}
